package com.api.controller;

import com.api.service.BaseService;
import com.api.util.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @packageName: com.api.controller
 * @name: BaseController
 * @description:
 * @author: 董定卓
 * @dateTime: 2019/6/12 16:20
 */
public abstract class BaseController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    protected abstract BaseService getService();

    /**
     * 分页
     *
     * @param map
     * @param page
     * @param limit
     * @return
     */
    public AjaxResult page(Map<String, Object> map, int limit, int page) {
        try {
            List<Map<String, Object>> data = this.getService().pagination(map, limit, page);
            long count = this.getService().count(map);
            return AjaxResult.successResultForPage(data, count);
        } catch (Exception e) {
            logger.error("获取数据分页列表失败：" + e.getMessage());
        }
        return AjaxResult.failResult("获取数据分页列表失败");
    }

}
